import pymysql
from db.db_config import get_current_config

# 连接池
connection_pool = {}


def get_connection():
    db_config = get_config()
    host = db_config['host']
    if host in connection_pool \
            and connection_pool[host] is not None \
            and connection_pool[host].open is True:
        return connection_pool[host]
    db_connection = pymysql.connect(host=host, user=db_config['user'], password=db_config['password'], charset='utf8',
                                    cursorclass=pymysql.cursors.DictCursor)
    connection_pool[host] = db_connection
    return db_connection
    pass


def get_config():
    return get_current_config(False)
    pass

